package edu.utn.tacs.grupouno.ui.server;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import edu.utn.tacs.grupouno.negocio.Estudio;
import edu.utn.tacs.grupouno.rest.api.EstudiosService;
import edu.utn.tacs.grupouno.ui.client.EstudiosUIService;
import edu.utn.tacs.grupouno.ui.client.dto.EstudioDTO;
import edu.utn.tacs.grupouno.ui.server.factories.EstudioDTOFactory;

public class EstudiosUIServiceImpl extends RemoteServiceServlet implements EstudiosUIService {

	private static final long serialVersionUID = -9029366065242785214L;
	private ClassPathXmlApplicationContext context;
	
	@Override
	public EstudioDTO getEstudio(String id) {
		try {
			if(context == null) {
				context = new ClassPathXmlApplicationContext("beans-ui.xml");
			}
			EstudiosService proxy = context.getBean("estudiosService", EstudiosService.class);
			Estudio estudio = proxy.getEstudio(id);
			EstudioDTOFactory factory = new EstudioDTOFactory();
			EstudioDTO dto = factory.create(estudio);
			return dto;
		} catch(Exception e) {
			e.printStackTrace();
			return null;
		}
	}

}
